package com.czkt.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.czkt.entity.BasDict;
import com.czkt.service.IBasDictService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2024-06-18
 */
@Controller
public class BasDictController {
    @Resource
    IBasDictService basDictService;

    /**
     * 客户等级
     * @param dictId 等级Id
     * @param dictItem 等级
     * @param pageIndex 当前页数
     * @param pageSize  每页记录数
     * @param model 传值
     * @return 跳到等级列表页面
     */
    @RequestMapping("/dict/list")
    public String dictListShow(@RequestParam(value = "dictId",defaultValue = "") String dictId,
                               @RequestParam(value = "dictItem",defaultValue = "") String dictItem,
                               @RequestParam(value = "pageIndex",defaultValue = "1") Integer pageIndex,
                               @RequestParam(defaultValue = "3") Integer pageSize, Model model){
        IPage<BasDict> basDictIPage = basDictService.selectBasDictList(dictId,dictItem,pageIndex,pageSize);
        model.addAttribute("dictPage",basDictIPage);
        model.addAttribute("dictId",dictId);
        model.addAttribute("dictItem",dictItem);
        return "/dict/list";
    }

    /**
     * 修改客户等级页面
     * @param dictId 等级Id
     * @param model 传值
     * @return 跳转到更新页面
     */
    @RequestMapping("/dict/edit")
    public String updateBasDict(String dictId,Model model){
        model.addAttribute("dict",basDictService.selectBasDict(dictId));
        return "/dict/edit";
    }

    /**
     * 修改等级
     * @param basDict 等级实体类
     * @return 修改成功跳转到等级列表
     */
    @RequestMapping("/crm/dict/save")
    public String toInsertBasDict(BasDict basDict){
        basDictService.toInsertBasDict(basDict);
        return "redirect:/dict/list";
    }
//    @RequestMapping("/crm/dict/del/{dictId}")
//    @ResponseBody
//    public Object deleteDictId(@PathVariable("dictId") String dictId){
//        Map<String,Object> resultMap = new HashMap<>();
//        basDictService.deleteBasDict(dictId);
//        resultMap.put("delResult","true");
//        return resultMap;
//    }

    /**
     * 添加等级页面
     * @return 跳转到等级添加页面
     */
    @RequestMapping("/dict/add")
    public String insertBasDict(){
        return "/dict/add";
    }

    /**
     * 添加等级
     * @param basDict 等级信息
     * @return 添加成功跳转到等级列表
     */
    @RequestMapping("/dict/save")
    public String toUpdateBasDict(BasDict basDict){
        basDictService.toUpdateBasDict(basDict);
        return "redirect:/dict/list";
    }


}
